How To Integrate Git With An Existing Website

alt: How To Convert An Existing Website Into A Git Repo

THIS GUIDE HAS NOT BEEN COMPLETELY TESTED YET

Did steps 3 and 4 on live production site/ directory (/var/www/site.com/html) but DID NOT DO STEP 5 (commit) yet.

https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

also see (& compare the above link with): https://tylercipriani.com/blog/2012/10/21/move-existing-website-to-git/

This guide shows how to setup git on an existing live production site you will then download into a local repository for development. After editing the site locally, you can then push the site changes back to the live production site.

1. Install the latest version of Git on Ubuntu (16.04)

http://stackoverflow.com/questions/19109542/installing-latest-version-of-git-in-ubuntu

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git

2. At the command line, give Git your name using the following command:

$ git config --global user.name "YOUR NAME"

Use the next command to give Git your email address. If you are going to use a hosted repository, use the email address here that you will use to sign up.

$ git config --global user.email "YOUR EMAIL ADDRESS"

You can see all of your settings with this command:

$ git config --list

3. Change into the project's root folder on the command line and use the “git init” command to start versioning this project:

$ cd path/to/project/folder
$ git init

A new, hidden folder was added named “.git”. All that happened is that Git created an empty local repository for us. Git did not add the current content of your working copy (working directory) as something like an “initial version”. The repository contains not a single version of your project, yet.

Working Copy

The root folder of your project is often called the “working copy” (or “working directory”). It's the directory on your local computer that contains your project's files. You can always ask the version control system to populate your working copy with any version of your project. But you always only have one working copy with one specific version on your disk – not multiple in parallel.

4. Create an empty file in your favorite editor and save it as “.gitignore” in your project's root folder. add a line for each file that you would like git to ignore.

For WordPress projects, below is an example of my default ‘.gitignore' settings. The ‘updraft' folder is for the ‘UpdraftPlus' plugin.

*.log
wp-config.php
wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/blogs.dir/
wp-content/cache/
wp-content/upgrade/
wp-content/uploads/
wp-content/wp-cache-config.php
wp-content/updraft/
wp-snapshots/

/.htaccess
/license.txt
/readme.html

The list of files to ignore is kept in a simple file called “.gitignore” in the root folder of your project. It's highly recommended to define this list at the very beginning of your project – before making your first commit. Because once files are committed, you'll have to jump through some hoops to get them out of version control, again.

Which Files Should I Ignore?

As a simple rule of thumb you'll most likely want to ignore files that were created automatically (as a “by-product”): temporary files, logs, cache files… Other examples for excluded files range from compiled sources to files that contain passwords or personal configurations. Templates can be viewed here https://github.com/github/gitignore

Ignore one specific file: Provide the full path to the file, seen from the root folder of your project.

path/to/file.ext

Ignore all files with a certain name (anywhere in the project): Just write down the file's name, without giving a path.

filename.ext

Ignore all files of a certain type (anywhere in the project):

*.ext

Ignore all files in a certain folder:

path/to/folder/*

5.We add our files and then commit the files:

$ git add .
$ git commit -m "Initial commit"

The comment in quotes after -m is a message describing the commit.

note: You may see a warning after the ‘git add -A” command like:

The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF...

You canignore this and/or turn this warning off by typing on the command line:

git config core.autocrlf true

http://stackoverflow.com/questions/5834014/lf-will-be-replaced-by-crlf-in-git-what-is-that-and-is-it-important

Other References: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

https://www.youtube.com/watch?v=MJFErVA0vfk

also see Using Git in Your Workflow

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.